home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / handson.exe / FRUNIT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-01-31  |  4.1 KB  |  116 lines

  1. unit Frunit;
  2. { PC Plus sample Delphi program. A simple French verb conjugator - mark 3 }
  3. { This now deals with regular ER, IR and RE verbs. It illustrates the use }
  4. { of standard Pascal procedures                                           }
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  10.   Forms, Dialogs, StdCtrls;
  11.  
  12. type
  13.   TForm1 = class(TForm)
  14.     ListBox1: TListBox;
  15.     Edit1: TEdit;
  16.     Label1: TLabel;
  17.     Button1: TButton;
  18.     procedure Button1Click(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure ConjugateERverb( vStem : string );
  33. { Note that this is a basic Pascal procedure rather than
  34.   an Object Pascal 'method'. Unlike the methods created by Delphi
  35.   itself, the procedure name does not use dot-notation
  36.          (e.g. Form1.someProcedureName)
  37.   For this reason, other Form1 methods are not automatically
  38.   'visible' to this procedure. This explains why we've had to
  39.   call these methods in this manner:
  40.           Form1.ListBox1.Items.Add('Je ' + vStem + 'e');
  41.   We could turn the procedure into a 'method' of Form1 by declaring it as:
  42.           Form1.ConjugateERverb
  43.   In which case, other Form1 methods would be visible, and could be
  44.   called using the syntax:
  45.           ListBox1.Items.Add('Je ' + vStem + 'e');
  46.   More on this next month! }
  47. begin
  48.    Form1.ListBox1.Items.Clear;
  49.    Form1.ListBox1.Items.Add('Je ' + vStem + 'e');
  50.    Form1.ListBox1.Items.Add('Tu ' + vStem + 'es' );
  51.    Form1.ListBox1.Items.Add('Il ' + vStem + 'e' );
  52.    Form1.ListBox1.Items.Add('Elle ' + vStem + 'e' );
  53.    Form1.ListBox1.Items.Add('Nous ' + vStem + 'ons' );
  54.    Form1.ListBox1.Items.Add('Vous ' + vStem + 'ez' );
  55.    Form1.ListBox1.Items.Add('Ils ' + vStem + 'ent');
  56.    Form1.ListBox1.Items.Add('Elles ' + vStem + 'ent');
  57. end;
  58.  
  59. procedure ConjugateREverb( vStem : string );
  60. begin
  61.    Form1.ListBox1.Items.Clear;
  62.    Form1.ListBox1.Items.Add('Je ' + vStem + 's');
  63.    Form1.ListBox1.Items.Add('Tu ' + vStem + 's' );
  64.    Form1.ListBox1.Items.Add('Il ' + vStem  );
  65.    Form1.ListBox1.Items.Add('Elle ' + vStem  );
  66.    Form1.ListBox1.Items.Add('Nous ' + vStem + 'ons' );
  67.    Form1.ListBox1.Items.Add('Vous ' + vStem + 'ez' );
  68.    Form1.ListBox1.Items.Add('Ils ' + vStem + 'ent');
  69.    Form1.ListBox1.Items.Add('Elles ' + vStem + 'ent');
  70. end;
  71.  
  72. procedure ConjugateIRverb( vStem : string );
  73. begin
  74.    Form1.ListBox1.Items.Clear;
  75.    Form1.ListBox1.Items.Add('Je ' + vStem + 'is');
  76.    Form1.ListBox1.Items.Add('Tu ' + vStem + 'is' );
  77.    Form1.ListBox1.Items.Add('Il ' + vStem + 'it' );
  78.    Form1.ListBox1.Items.Add('Elle ' + vStem + 'it' );
  79.    Form1.ListBox1.Items.Add('Nous ' + vStem + 'issons' );
  80.    Form1.ListBox1.Items.Add('Vous ' + vStem + 'issez' );
  81.    Form1.ListBox1.Items.Add('Ils ' + vStem + 'issent');
  82.    Form1.ListBox1.Items.Add('Elles ' + vStem + 'issent');
  83. end;
  84.  
  85. procedure TForm1.Button1Click(Sender: TObject);
  86. var                  { --- Declare 3 string variables --- }
  87.   verb,              { the verb specified by the user     }
  88.   verbStem,          { the verb minus its 2-letter ending }
  89.   verbEnd : string;  { the 2-letter ending                }
  90. begin
  91.   verb := Edit1.Text;
  92.        { check that the user has entered something... }
  93.   if verb = '' then
  94.      Caption := 'You must enter a verb!'
  95.   else
  96.   begin {... if so, then                              }
  97.         { find the stem and the ending of the verb    }
  98.     verbStem := copy( verb, 1, length(verb)-2 );
  99.     verbEnd  := copy( verb, length(verb) -1, 2 );
  100.     Caption  := 'This is an ' + verbEnd + ' verb.';
  101.         { find type of verb and call appropriate proc }
  102.     if LowerCase( verbEnd ) = 'er' then
  103.        ConjugateERverb( verbStem )
  104.     else
  105.     if LowerCase( verbEnd ) = 're' then
  106.        ConjugateREverb( verbStem )
  107.     else
  108.     if LowerCase( verbEnd ) = 'ir' then
  109.        ConjugateIRverb( verbStem )
  110.     else         { if this isn't an ER, RE or IR verb, show error msg... }
  111.        Caption := 'You must enter an ER, RE or IR verb!';
  112.   end;
  113. end;
  114.  
  115. end.
  116.